package handlers

import (
	"code.google.com/p/jesus-1496/auth/sessionshelper"
	"code.google.com/p/jesus-1496/servererror"
	"code.google.com/p/jesus-1496/settings"
	"code.google.com/p/jesus-1496/utils/env"

	"net/http"
)

type logoutData struct {
	Message string
	HomeUrl string
}

func LogoutHandler(w http.ResponseWriter, r *http.Request) *servererror.ServerError {
	sessionshelper.LogUserOut(w, r) //Ignore error
	t, _, err := env.NewHtmlTemplateFromFile("logged_out.html")
	if err != nil {
		return servererror.NewServerError(err, "Internal server error.", http.StatusInternalServerError)
	}

	ld := logoutData{"Logged out successfully.", settings.Settings.Web.HomeUrl}

	w.Header().Set("Content-Type", "text/html")
	err = t.Execute(w, ld)
	if err != nil {
		return servererror.NewServerError(err, "Internal server error.", http.StatusInternalServerError)
	}

	return nil
}
